package cn.com.twoke.get_xml_data.config;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolConfiguration {

    public static final ExecutorService EXECUTOR_SERVICE = executorService();

    private static ExecutorService executorService() {
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(
                availableProcessors,
                availableProcessors * 2,
                0,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(availableProcessors),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }

}
